package middlewares

import (
	"MyBlogs/pkg/session"
	"github.com/gin-gonic/gin"
	"net/http"
)

func CheckAdmin(context *gin.Context) {
	var name string
	var id int64 //TODO 未完成
	values := session.GetAdminSession(context)

	if v, ok := values["name"]; ok {
		name = v.(string)
	}

	if v, ok := values["id"]; ok {
		id = v.(int64)
	}

	if name == "" || id <= 0 {
		context.Redirect(http.StatusFound, "/admin/login")

		context.Abort()

		return
	}

	context.Next()
}
